package day06.Ti;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Scanner;

public class Ti01Date {
    public static void main(String[] args) throws ParseException {
//        请编写程序，从控制台接收一个“生日”，格式：yyyy-MM-dd，
//        程序要能够计算并打印他来到世界xx天。
        mether01();
        mether02();
    }

    private static void mether02() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate brithday = LocalDate.parse(s, dtf);
        long day = brithday.until(LocalDate.now(), ChronoUnit.DAYS);
        if (day <= 0) {
            System.out.print("生日必须早于当前日期！");
        } else {
            System.out.println("您已经来到这个世界" + day + "天了");
        }
    }

    private static void mether01() throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的生日(格式yyyy-MM-dd):");
        String s = sc.next();
        SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd");
//        String format = time.format(s);  转换为字符串格式
        Date birthday = time.parse(s);
//        转换为时间格式
        long birthdayTime = birthday.getTime();
        long l = System.currentTimeMillis() - birthdayTime;
        long day = l / 1000 / 60 / 60 / 24;
        if (day <= 0) {
            System.out.print("生日必须早于当前日期！");
        } else {
            System.out.println("您已经来到这个世界" + day + "天了");
        }

    }
}
